package com.qf.news.controller;

import com.qf.news.domain.Admin;

import com.qf.news.response.Response;
import com.qf.news.service.AdminService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

@RestController
@RequestMapping("Admin")
@RequiredArgsConstructor
public class AdminController {

    private final AdminService adminService;

    @PostMapping("/adminLogin")
    public Response<Admin> login(@RequestBody Admin admin) {

        Admin adminLogin = adminService.adminLogin(admin.getUsername(),admin.getUserpwd());
        if (Objects.nonNull(adminLogin)) {
            System.out.println("成功");
            return Response.success(adminLogin);

        } else {
            System.out.println("失败");
            return Response.fail();
        }
    }

    @PostMapping("deleteUser")
    public Response<Admin> deleteUser(@RequestBody Admin admin) {
adminService.deleteuser(String.valueOf(admin));
        return Response.success();
    }
    @PostMapping("deleteLuoyanguser")
    public Response<Admin> addUser(@RequestBody Admin admin) {
adminService.deleteLuoyangyuser(String.valueOf(admin));
        return Response.success();
    }
}
